import TableData from "@/components/public/el-table-pagination"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyoutDetail.vue'
import CustomDialog from "@/components/materialQualityPage/sampleManage/fieldSampling/index.vue";
// import publicForm from "@/components/materialDataManage/fromCom.vue";  //模糊查询
// import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置
// import axios from "axios";
import {
    getSampleWorkWebList, //列表
} from "@/api/request.js";
export default {
    inject: ["reload"],
    name: "collectionText",
    data() {
        return {
            name: "collectionText",
            radio: "待办",
            // 列表
            treelength: true, //左侧树显示隐藏
            btnObj: [], //按钮
            queryCriteriaData: {},
            loading: false, //列表转载
            getList: {
                fCompanyid: "", // 左侧选中组织机构id
                userId: "", // 查询待办或已办时传 列表页查询不传
                fSamplemodel: "", // 上方查询条件样品种类  对应code
                fSamplename: "", // 上方查询条件样品名称
                fStatus: "", // 上方查询条件样品状态registerList
                startDates: "", //取样日期开始时间
                endDates: "", //取样日期结束时间
                modelType: "3", // 取样：0-待办 1-已办;收样：3-待办 4-已办；查看：传2
                page: 1, // 当前页码
                pageSize: 20, // 每页显示条数
            },
            isShow: false, //是否显示弹框
            statusNum: null, //点击那个按钮
            table_config: formJs.table_config,
            dataFid: null, //列表详情id
            currentRow: null, //当前行信息
            tableData: [], //表格列表数据列表
            dialogTitle: null,
            displaySwitching: 2, //2取样&收样；0取样；1收样
            // 列表
            userInfo: {}, //登录用户
        };
    },
    components: {
        TableLyout,
        TableData, //主页面列表
        CustomDialog
    },
    created() {},
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        // console.log("userInfo", this.userInfo);
        this.getList = {
            fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
            userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
            fSamplemodel: "", // 上方查询条件样品种类  对应code
            fSamplename: "", // 上方查询条件样品名称
            fStatus: "", // 上方查询条件样品状态
            startDates: "", //取样日期开始时间
            endDates: "", //取样日期结束时间
            modelType: "3", // 取样：0-待办 1-已办;收样：3-待办 4-已办；查看：传2
            page: 1, // 当前页码
            pageSize: 20, // 每页显示条数
        };

        this.yj_searchForm(this.getList);
        this.btnRole(this.name);

        this.table_config.operation.cols = [{
            prop: "fStatus",
            type: "primary",
            handleRow: this.handleRow,
        }, ];

        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;
            if (rowData == "待取样") {
                color = "red !important";
            } else if (rowData == "待收样") {
                color = "orange !important";
            } else if (rowData == "已收样") {
                color = "green !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };
    },
    methods: {
        refreshList() { //刷新列表

            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        handleRow() {},

        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj;
            }
        },
        modelType(e) {
            this.currentRow = "";
            this.dataFid = "";
            this.getList.userId = this.userInfo.userId;
            if (e == "待办") {
                this.getList.modelType = "3";
            } else {
                this.getList.modelType = "4";
            }
            this.yj_searchForm(this.getList);
        },
        closeDialog() {
            this.isShow = false;
        },
        getBtnName(name, status) {
            this.statusNum = status;
            this.yj_edit(status);
        },
        // 新增/编辑
        yj_edit(num) {
            if (num == 5) { //导出
                if (this.dataFid != null) {
                    this.$message.warning("该功能正在卖力开发中");  
                } else {
                    this.$message.warning("请先选择需要导出的数据");
                }
            } else {
                if (this.userInfo.userId != "System") {
                    this.statusNum = num;
                    if (num == 3) { // 编辑
                        this.dialogTitle = "编辑收样信息";
                        if (this.dataFid != null) {
                            this.editText();
                        } else {
                            this.$message.warning("请先选择需要编辑的数据");
                        }
                    }
                } else {
                    this.$message.warning("该用户无权限");
                }
            }
        },
        editText() {
            this.isShow = true;
        },
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "取样编号") {
                this.statusNum = 7;
                this.dialogTitle = "查看样品信息";
                this.currentRow = row;
                this.isShow = true;
            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(id) {
            this.loading = true;
            getSampleWorkWebList(id)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        that.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                    console.log("获取列表数据接口报错");
                });
        },
        // 导出
        Print() {
            console.log("导出需要链接");
        },
    },
};